package com.gin.kotlin.gf2gamecommunity.viewmodel

import androidx.lifecycle.ViewModel
import com.gin.kotlin.gf2gamecommunity.app.App
import com.gin.kotlin.gf2gamecommunity.base.livedata.CachedLiveData
import com.gin.kotlin.response.ListData
import com.gin.kotlin.response.Res
import com.gin.kotlin.response.index.Banner
import com.gin.kotlin.response.strategy.StrategyGroup
import com.gin.kotlin.response.theme.HotTheme
import com.gin.kotlin.response.topic.TopicCategory

/**
 * 首页 - 社区
 * @property banners 轮播图
 * @property categories 主题版面（分类）
 * @property strategyGroups 攻略分组
 * @property hotThemes 热门话题
 * @constructor
 */
class CommunityIndexViewModel : ViewModel() {

    val banners = CachedLiveData<Res<Banner.Body>, List<Banner>>(
        requestMethod = { App.INSTANCE.api.indexApi.getBanner() },
        bodyTransform = { it.data?.bannerList },
    )

    val categories = CachedLiveData<Res<ListData<TopicCategory>>, List<TopicCategory>>(
        requestMethod = { App.INSTANCE.api.indexApi.getCategoryList() },
        bodyTransform = { it.data?.list },
    )

    val strategyGroups = CachedLiveData<Res<List<StrategyGroup>>, List<StrategyGroup>>(
        requestMethod = { App.INSTANCE.api.strategyApi.getGroups() },
        bodyTransform = { it.data },
    )

    val hotThemes = CachedLiveData<Res<HotTheme.List>, List<HotTheme>>(
        requestMethod = { App.INSTANCE.api.themeApi.getHotTheme() },
        bodyTransform = { it.data?.themeList },
    )

}